import request from '@/utils/request'

export interface AccountDTO {
  accountId?: string
  accountCode: string
  accountName: string
  parentId?: string
  accountType?: string // ASSET/LIABILITY/EQUITY/REVENUE/EXPENSE
  dcFlag?: string // DEBIT/CREDIT
  levelNum?: number
  isLeaf?: number
  status?: number
  remark?: string
}

export function pageAccount(params: { pageNum?: number; pageSize?: number; accountCode?: string; accountName?: string; accountType?: string; status?: number }) {
  return request({ url: '/erp/account/page', method: 'get', params })
}

export function getAccount(id: string) {
  return request({ url: `/erp/account/${id}`, method: 'get' })
}

export function getAccountByCode(code: string) {
  return request({ url: `/erp/account/code/${code}`, method: 'get' })
}

export function treeAccount() {
  return request({ url: '/erp/account/tree', method: 'get' })
}

export function createAccount(data: AccountDTO) {
  return request({ url: '/erp/account', method: 'post', data })
}

export function updateAccount(id: string, data: AccountDTO) {
  return request({ url: `/erp/account/${String(id)}`, method: 'put', data })
}

export function deleteAccount(id: string) {
  return request({ url: `/erp/account/${String(id)}`, method: 'delete' })
}

